package cst.a802yp.startproj;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a802yp.startproj.bean.WeatherInfo;
import cst.a802yp.startproj.listener.WeatherListener;
import cst.a802yp.startproj.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements WeatherListener,View.OnClickListener{
    private EditText et_citynumber;
    private TextView tv_cityname;
    private Button btn_find1;
    private Button btn_find2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }
    private void init(){
        et_citynumber= (EditText) findViewById(R.id.editText_cityno);
        tv_cityname= (TextView) findViewById(R.id.textView3);
        btn_find1= (Button) findViewById(R.id.button);
        btn_find2= (Button) findViewById(R.id.button2);
        btn_find1.setOnClickListener(this);
        //btn_find1.setOnClickListener(new View.OnClickListener() {
           // @Override
           // public void onClick(View v) {

         //   }
       // });
    }

    @Override
    public void onResponse(WeatherInfo weather) {
        if (weather!=null){
            tv_cityname.setText(weather.getCity());
        }
        else {
            tv_cityname.setText("未知");
        }

    }

    @Override
    public void onFail(String msg) {
        tv_cityname.setText("失败");

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //ctrl+alt+i
            case R.id.button:
                WeatherModel weatherModel= new WeatherModel();
                weatherModel.getWeather(et_citynumber.getText().toString(),this);
                break;
            case R.id.button2:
                break;
            default:
                break;

        }
    }
}
